import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sample/src/gpt_markdown.dart';
import 'package:flutter_sample/src/routes.dart';
import 'package:gpt_markdown/gpt_markdown.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:leak_tracker/leak_tracker.dart';
import 'package:watcher/watcher.dart';

void main() {
  LeakTracking.start();
  // Dispatch memory events from the Flutter engine to LeakTracking.
  FlutterMemoryAllocations.instance.addListener(
        (ObjectEvent event) => LeakTracking.dispatchObjectEvent(event.toMap()),
  );

  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ThemeMode _themeMode = ThemeMode.dark;
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: routers,
      debugShowCheckedModeBanner: false,
      locale: Locale.fromSubtags(languageCode: 'zh'),
      localizationsDelegates: GlobalMaterialLocalizations.delegates,
      supportedLocales: const [
        Locale('en', ''),
        Locale('zh', ''),
        Locale('he', ''),
        Locale('es', ''),
        Locale('ru', ''),
        Locale('ko', ''),
        Locale('hi', ''),
        Locale('ja', ''),
        Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant')
      ],
      title: 'Flutter Demo',
      themeMode: _themeMode,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
        brightness: Brightness.light,
        extensions: [
          GptMarkdownThemeData(
            brightness: Brightness.light,
            highlightColor: Colors.red,
          ),
        ],
      ),
      darkTheme: ThemeData(
        useMaterial3: true,
        brightness: Brightness.dark,
        colorSchemeSeed: Colors.blue,
        extensions: [
          GptMarkdownThemeData(
            brightness: Brightness.dark,
            highlightColor: Colors.red,
          ),
        ],
      ),
    );
  }
}
